package b面向对象.day3.demo8_多态;

public class Ghost {
    public static Person getPerson(int choice){
        Person p;
        switch (choice){
            case 0:
                p=new Teacher();
                break;
            case 1:
                p=new Stu();
                break;
            case 2:
                p=new Officer();
                break;
            default:
                p=new Person();
        }
        return p;
    }
    //参数类型多态
    public static void eatPerson(Person p){
        if(p instanceof Teacher){
//            Teacher t=(Teacher) p;
//            t.edu();
            ((Teacher)p).edu();
        }else if(p instanceof Officer){
            ((Officer) p).work();
        }
        p.say();
    }
}
